package com.rh.number.enums;

public enum UserRole {
    USER(1, "普通用户"),
    ADMIN(2, "管理员");

    private final int code;
    private final String desc;

    UserRole(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static UserRole fromCode(Integer code) {
        if (code == null) return USER;
        for (UserRole role : values()) {
            if (role.code == code) return role;
        }
        throw new IllegalArgumentException("无效角色代码");
    }

    public String getDesc() {
        return desc;
    }
}